package 多线程练习;

public class _1_100 {
      public static void main(String[] args) {
            System.out.println("方式一");
            T w = new T();//公用同一个对象
            Thread t1 = new Thread(w);
            Thread t2 = new Thread(w);

            t1.setName("窗口1");
            t2.setName("窗口2");

            t1.start();
            t2.start();

      }
}

class T extends Thread {

      private int number = 1;
      private Object obj = new Object();

      @Override
      public void run() {
            try {
                  synchronized (obj) {
                        while (number <= 100) {
                              obj.notify();
                              Thread.sleep(10);
                              System.out.println(Thread.currentThread().getName() + ":" + number);
                              number++;
                              //使得调用如下wait()方法的线程进入阻塞状态
                              obj.wait();
                        }
                  }
            } catch (InterruptedException e) {
                  e.printStackTrace();
            }
      }
}
